package util

import (
	"bytes"
	"golang.org/x/text/encoding/simplifiedchinese"
	"golang.org/x/text/transform"
	"io/ioutil"
)

func GBK2UTF8Bytes(utf8bytes []byte) ([]byte, error) {
	return ioutil.ReadAll(transform.NewReader(bytes.NewReader(utf8bytes), simplifiedchinese.GBK.NewDecoder()))
}

func GBK2UTF8String(utf8bytes []byte) (string, error) {
	tmp, err := ioutil.ReadAll(transform.NewReader(bytes.NewReader(utf8bytes), simplifiedchinese.GBK.NewDecoder()))
	if err != nil {
		return "", err
	}
	return string(tmp), nil
}
